<template>
  <el-dialog
    :visible.sync="modal"
    title="课程列表"
    width="70%"
    custom-class="plan-course-list-dialog"
  >

    <div class="head">
      <div class="input">
        <span>课程名称：</span>
        <el-input v-model="queryData.course_name" placeholder="请输入" />
      </div>
      <div class="input">
        <span>培训类型：</span>
        <el-cascader
          :options="typeList"
          v-model="queryData.type_id"
          :props="{ multiple: false, checkStrictly: true }"
          @change="handleChange"
          clearable
        ></el-cascader>
      </div>
      <el-button type="primary" class="btn" @click="search">查询</el-button>
      <el-button type="primary" class="btn" @click="reset">重置</el-button>
    </div>
    <div class="box">
      <el-table
        :data="tableData"
        border
        v-loading="isTableLoading"
        empty-text="暂无数据"
        no-filtered-userFrom-text="暂无筛选结果"
        style="width: 100%"
      >
        <el-table-column fixed type="index" align="center" label="序号" width="50" />
        <el-table-column fixed prop="course_name" align="center" show-overflow-tooltip label="课程名称" min-width="140" />
        <el-table-column prop="ware_count" align="center" label="课件数量" width="100"></el-table-column>
        <el-table-column prop="merchantType.name" align="center" label="企业类型" width="140"></el-table-column>
        <el-table-column prop="type_name" align="center" label="培训类型" width="140"></el-table-column>
        <el-table-column prop="create_time" align="center" label="创建时间" width="140"></el-table-column>
      </el-table>
      <div class="acea-row row-right page">
      <el-pagination
        style="margin-top: 5px"
        @size-change="search"
        @current-change="search"
        :current-page.sync="queryData.page"
        :page-size.sync="queryData.size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
      </div>
    </div>

  </el-dialog>
</template>

<script>
import request from '../../libs/request'
export default {
  name: 'cultivate',
  props: {
    typeList: {
      type: Array,
    }
  },
  data() {
    return {
      queryData: {
        plan_id: '',
        course_name: '',
        type_id: '',
        page: 1,
        size: 10,
      },
      modal: false,
      total: 0,
      isTableLoading: false,
      tableData: [],
      dialogVisible: false,
      options2: [],
    };
  },
  computed: {},
  created() {},
  mounted() {},
  methods: {
    showModal(id) {
      this.queryData.plan_id = id
      this.modal = true
      this.getList()
    },
    search(d) {
      if (typeof d == 'number') {
        this.queryData.page = d
      } else {
        this.queryData.page = 1;
      }
      this.getList();
    },
    reset() {
      this.queryData.course_name = '';
      this.queryData.type_id = '';
      this.search();
    },
    getList() {
      this.isTableLoading = true;
      this.tableData = [];
      request({
        url: '/course/list',
        method: 'post',
        params: this.queryData,
      }).then(res => {
        this.tableData = res.data.list;
        this.total = res.data.total;
      })
      this.isTableLoading = false;
    },
    back() {
      this.modal = false
      this.reset()
    },
    handleChange(value) {
      if (value) {
        this.queryData.type_id = value[value.length - 1];
      }
    },
  },
};
</script>

<style scoped>
.head {
  width: 100%;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  background: #ffffff;
  border-radius: 5px;
  padding: 20px;
  padding-bottom: 0px;
}

.input {
  display: flex;
  align-items: center;
  margin-right: 15px;
  margin-bottom: 20px;
}

.input > span {
  font-size: 12px;
  flex-shrink: 0;
}

.btn {
  margin-bottom: 20px;
}

.box {
  width: 100%;
  background: #ffffff;
  border-radius: 5px;
  padding: 20px;
  margin-top: 20px;
}

.action {
  display: flex;
  align-items: center;
  justify-content: center;
}

.action span {
  color: #0256ff;
  font-size: 12px;
  cursor: pointer;
  margin: 0 8px;
}

.flex {
  width: 100%;
  align-items: center;
  margin-bottom: 20px;
}
</style>
<style>
.plan-course-list-dialog .el-dialog__body {
  height: 70vh;
}
</style>